#!/usr/bin/env bash

export DEBIAN_FRONTEND=noninteractive
ufw disable
apt-get -q -y update

SITE_PATH='/var/www/drupal7'

# Create Database instance
mysql -u root -e "use mysql;update user set host = '%';"
mysql -u root -e "GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '' WITH GRANT OPTION;"
mysql -u root -e "flush privileges;"
mysql -u root -e "create database drupal7;"

# Install PHP
apt-get -q -y install php5-gd

# apache2
#apt-get -y install apache2
a2enmod rewrite
echo "
<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot $SITE_PATH
		ServerName 192.168.33.10
		
		<Directory '$SITE_PATH'>
			Options Indexes FollowSymLinks MultiViews
			AllowOverride All
			Order allow,deny
			allow from all
		</Directory>
</VirtualHost>
" > /etc/apache2/sites-available/drupal7.conf
a2ensite drupal7.conf

# auto start
echo "#!/bin/sh -e
service apache2 start
exit 0" > /etc/rc.local

service apache2 restart

# Post Up Message
echo "请访问 http://192.168.33.10/"